function validateForm(){
	if($('#harian').val()==''||$('#inap').val()==''){
		alert('Anda Harus Set Dulu Biaya Perjalanan Sebelum Input Anggota Tim');
		return false;
	}else{
		var total = parseInt($('#total').val());
		var totalgrid = decomMoney($('#totalBiaya').val());
		var anggaran = decomMoney($('#Kegiatan_anggaran').val());
		var trans = parseInt($('#Tim_biaya_trans').val());
		var airport = parseInt($('#Tim_airportax').val());
		var riil = parseInt($('#Tim_riil').val());
		
		var tot_all = total+totalgrid+trans+airport+airport;
		if(anggaran<tot_all){
			alert('Anggaran Tidak Mencukupi Anggaran : '+anggaran+' < '+tot_all);
			return false
		}
		else{return true;}
	}
	
}
function validateFormUpdate(){
	if($('#harian').val()==''||$('#inap').val()==''){
		alert('Anda Harus Set Dulu Biaya Perjalanan Sebelum Input Anggota Tim');
		return false;
	}else{
		var total = parseInt($('#total').val());
		var totalgrid = decomMoney($('#totalBiaya').val());
		var anggaran = decomMoney($('#Kegiatan_anggaran').val());
		var trans = parseInt($('#Tim_biaya_trans').val());
		var airport = parseInt($('#Tim_airportax').val());
		var riil = parseInt($('#Tim_riil').val());
		var awal = parseInt($('totalAwal').val());
		
		var tot_all = (totalgrid - awal)+(total+airport+riil+awal);
		if(anggaran<tot_all){
			alert('Anggaran Tidak Mencukupi Anggaran : '+anggaran+' < '+tot_all);
			return false
		}
		else{return true;}
	}
	
}
$('#Tim_id_kary').change(function() {
	if(($('#Tim_tgl_mulai').val()!='') && ($('#Tim_tgl_berakhir').val()!='')&& ($('#Tim_biaya_trans').val()!='')&& ($('#Tim_riil').val()!='')){
		$.ajax({
			url: baseurl+"/index.php/tim/selBiaya",
			data: {
				id_provinsi:$('#Kegiatan_id_provinsi').val(),
				id_kary:$('#Tim_id_kary').val(),
			},
			dataType: "json",
			success: function(data) {
				if (data.res[0].code == 1) {
					// $("#hidtim").css("display","block");
					$('#harian').val(data.res[0].biaya_harian);
					$('#inap').val(data.res[0].biaya_penginapan);
					$('#tpd').val(data.res[0].nama_type_dinas);
					var trans = parseInt($('#Tim_biaya_trans').val());
					var airport = "";
					if($('#Tim_airportax').val() == ''){airport=0;}
					else {airport = parseInt($('#Tim_airportax').val());}
					var riil = parseInt($('#Tim_riil').val());
					hari = $('#jmlh').val();
					var total = (parseInt($('#harian').val())*parseInt(hari))+(parseInt($('#inap').val())*parseInt(hari));
					$('#total').val(total+trans+airport+riil);
				}
			}
		});
	}
	
});
$('#Tim_id_transport').change(function() {
	if($('#Tim_id_transport').val()=='2'){
		$("#Tim_airportax").removeAttr("disabled");		
	}else {
		$('#Tim_airportax').val('');
		$('#Tim_airportax').attr('disabled', true);
	}	
});

// $('#searchKar[data-toggle="modal"]').click(function(e) {
  // $('#winKary').load(baseurl+"/index.php/Karyawan/popup");
// });

$("#namakar").keypress(function(e) {
	if (e.keyCode == 115){
		$('#winKary').load(baseurl+"/index.php/Karyawan/popup");
		$("#winKary").modal('show');
	}
});

function chKary(id,nama){
    if(id){
		
		if(($('#Tim_tgl_mulai').val()!='') && ($('#Tim_tgl_berakhir').val()!='')&& ($('#Tim_biaya_trans').val()!='')&& ($('#Tim_riil').val()!='')){
			$("#Tim_id_kary").val(id);
			$("#namakar").val(nama);
			$.ajax({
				url: baseurl+"/index.php/tim/selBiaya",
				data: {
					id_provinsi:$('#Tim_id_provinsi').val(),
					id_kary:$('#Tim_id_kary').val(),
				},
				dataType: "json",
				success: function(data) {
					if (data.res[0].code == 1) {
						// $("#hidtim").css("display","block");
						$('#harian').val(data.res[0].biaya_harian);
						$('#inap').val(data.res[0].biaya_penginapan);
						$('#tpd').val(data.res[0].nama_type_dinas);
						var trans = parseInt($('#Tim_biaya_trans').val());
						var airport = "";
						if($('#Tim_airportax').val() == ''){airport=0;}
						else {airport = parseInt($('#Tim_airportax').val());}
						var riil = parseInt($('#Tim_riil').val());
						hari = $('#jmlh').val();
						var total = (parseInt($('#harian').val())*parseInt(hari))+(parseInt($('#inap').val())*parseInt(hari));
						$('#total').val(total+trans+airport+riil);
					}
				}
			});
		}
		else{
			alert('Anda Harus mengisi dahulu Tgl mulai,Tanggal selesai,biaya tansport,biaya riil untuk melakukan penjumlahan total dan pemilihan karyawan.');
		}
    }
    $('#winKary').modal('hide');
}